﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LuaInterface;
using UnityEditor;

public class TestLuaScriptObject : MonoBehaviour
{
	LuaState Lua;
	LuaLooper looper;
	[SerializeField]
	TextAsset text;
    // Start is called before the first frame update
    void Start()
    {
		//var LuaResLoader =  new LuaResLoader();
		//LuaResLoader.AddSearchPath(Application.dataPath + "/ResourceUpdate/Scripts");
		Lua = new LuaState();
		Lua.Start();
		LuaBinder.Bind(Lua);

		looper = gameObject.AddComponent<LuaLooper>();
		looper.luaState = Lua;

		Lua.DoString(text.text, text.name);


		LuaFunction luaFunction = Lua.GetFunction("TestCor", true);
		
		if (null != luaFunction)
		{
			luaFunction.BeginPCall();
			luaFunction.PCall();
			luaFunction.EndPCall();
			luaFunction.Dispose();
			luaFunction = null;
		}
	}

	private void Update()
	{
		Debug.Log("===== update========");
	}
	public void LateUpdate()
	{
		Debug.Log(">>>>> Laterupdate <<<<<<");
	}

	private void OnApplicationQuit()
	{
		looper.Destroy();
		Lua.CheckTop();	
		Lua.Dispose();
		looper = null;
		Lua = null;
	}
}
